package com.ftg.learn.ai.text2image;

import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversation;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationParam;
import com.alibaba.dashscope.aigc.multimodalconversation.MultiModalConversationResult;
import com.alibaba.dashscope.common.MultiModalMessage;
import com.alibaba.dashscope.common.Role;
import com.alibaba.dashscope.exception.NoApiKeyException;
import com.alibaba.dashscope.exception.UploadFileException;
import com.alibaba.dashscope.utils.Constants;

import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.Map;

/**
 * @author 布衣
 */
public class CreateImages {

    public static void create() throws NoApiKeyException, UploadFileException {
        //给定key
        Constants.apiKey = "sk-44547a4c94fc4ccdb0c99c0dfdbe5f1d";
        //没有要地址
        Constants.baseHttpApiUrl = "https://dashscope.aliyuncs.com/api/v1";

        MultiModalConversation mmc = new MultiModalConversation();

        MultiModalMessage message = MultiModalMessage.builder()
                .role(Role.USER.getValue())
                .content(Arrays.asList(Collections.singletonMap("text","一张 C4D 风格的电商促销海报，画面以粉色为主色调，整体呈现出清新、活泼的氛围。海报上方有巨大的 “老康 双十一 顶” 立体文字，视觉冲击力强。中间是一袋蓝色的宠物食品，包装上有透明窗口展示内部的肉块，包装显示品牌名字“萌宠家园”，旁边有一只可爱的猫咪。周围还有一些小型的动物模型和蓝色的机械设备，营造出一种热闹的促销场景。底部有红色的 “全场满 399 元减 99” 字样，突出了促销信息")))
                .build();

        Map<String, Object> parameters = new HashMap<>();
        parameters.put("watermark", true);
        parameters.put("prompt_extend", true);
        parameters.put("negative_prompt", "");
        parameters.put("size", "1328*1328");

        MultiModalConversationParam param = MultiModalConversationParam.builder()
                .model("qwen-image")
                .messages(Collections.singletonList(message))
                .parameters(parameters)
                .build();

        MultiModalConversationResult result = mmc.call( param);

        System.out.println(result+"结果");
    }

    public static void main(String[] args) {
        try {
            CreateImages.create();
        } catch (NoApiKeyException | UploadFileException e) {
            throw new RuntimeException(e);
        }
    }

}
